import 'dart:math';
import 'package:flutter/material.dart';

class StickersFloat extends StatefulWidget {
  const StickersFloat({super.key});

  @override
  State<StickersFloat> createState() => _StickersFloatState();
}

class _StickersFloatState extends State<StickersFloat>
    with SingleTickerProviderStateMixin {
  late final AnimationController _c;

  @override
  void initState() {
    super.initState();
    _c = AnimationController(vsync: this, duration: const Duration(seconds: 6))
      ..repeat();
  }

  @override
  void dispose() {
    _c.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final cs = Theme.of(context).colorScheme;
    return IgnorePointer(
      child: AnimatedBuilder(
        animation: _c,
        builder: (context, _) {
          final t = _c.value;
          return Stack(
            children: [
              _floating(
                context,
                left: 12,
                top: 160 + sin(t * 2 * pi) * 8,
                bg: cs.primaryContainer,
                icon: Icons.emoji_events,
              ),
              _floating(
                context,
                right: 24,
                top: 220 + sin(t * 2 * pi + 1) * 10,
                bg: cs.secondaryContainer,
                icon: Icons.rocket_launch,
              ),
              _floating(
                context,
                left: 40,
                bottom: 120 + sin(t * 2 * pi + 2) * 12,
                bg: Colors.amber.withOpacity(0.25),
                icon: Icons.star_rate_rounded,
              ),
            ],
          );
        },
      ),
    );
  }

  Widget _floating(
    BuildContext context, {
    double? left,
    double? right,
    double? top,
    double? bottom,
    required Color bg,
    required IconData icon,
  }) {
    return Positioned(
      left: left,
      right: right,
      top: top,
      bottom: bottom,
      child: Container(
        width: 36,
        height: 36,
        decoration: BoxDecoration(
          color: bg,
          borderRadius: BorderRadius.circular(12),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.06),
              blurRadius: 8,
              offset: const Offset(0, 4),
            ),
          ],
        ),
        child: Icon(
          icon,
          size: 20,
          color: Theme.of(context).colorScheme.primary,
        ),
      ),
    );
  }
}
